home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1989 / 02 / pmdev2 / spmtpl.c < prev    next >
Text File  |  1988-11-28  |  3KB  |  130 lines

  1. /* updated Oct. 18, 1988 to work with SDK 4.99 */
  2.  
  3. #define INCL_PM
  4. #include <os2.h>
  5. #include <stddef.h>
  6. #include <string.h>
  7.  
  8. #define EXTERN            /* all globals are declared in this module */
  9. #include "spmtpl.h"
  10.  
  11. /* local function declarations */
  12. void MainWndPaint(HWND hWnd, HPS hPS);
  13. BOOL WindowIsIconic(HWND hWnd);
  14.  
  15. #ifdef PMAUX
  16. #include <stdlib.h>
  17. #include <auxprt.h>
  18. #endif
  19.  
  20. /* entry point for program */
  21. int cdecl main(int argc, char *argv[])
  22. {
  23.  
  24.     QMSG qmsg;
  25.  
  26.   /* call initialization */
  27.     if (!InitProgram(argc, argv))
  28.     return FALSE;
  29.  
  30.   /* fall into message loop */
  31.     while (WinGetMsg(hAB, (PQMSG)&qmsg, (HWND)NULL, 0, 0))
  32.         WinDispatchMsg( hAB, (PQMSG)&qmsg );
  33.  
  34.   /* program exit */
  35.     WinDestroyWindow(hwndFrame);
  36.     WinDestroyMsgQueue(hmqMsgQ);
  37.     WinTerminate(hAB);
  38. }
  39.  
  40. /* main window message loop */
  41. MRESULT FAR PASCAL MainWndProc(HWND hWnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  42. {
  43.  
  44.     HPS hPS;        /* handle to PM display context */
  45.  
  46. #ifdef PMAUX
  47.     static int msgnum;
  48.     sprintf(auxbuf,"%4d hWnd = %8lx msg = %4x mp1 = %8lx mp2 = %8lx\n",
  49.                  msgnum, hWnd, msg, mp1, mp2);
  50.     msgnum += 1;
  51.     auxprt(auxbuf);
  52. #endif
  53.  
  54.     switch (msg) {
  55.  
  56.     case WM_CREATE:        /* called when main window is created */
  57.         WndCreate(hWnd);
  58.         break;
  59.  
  60.     case WM_CLOSE:        /* called when main window is closed */
  61.             WinPostMsg(hWnd, WM_QUIT, 0L, 0L) ;
  62.             break;
  63.  
  64.        case WM_PAINT:        /* called when window needs repainting */
  65.         hPS = WinBeginPaint(hWnd, (HPS)NULL, (PRECTL)NULL);
  66.         MainWndPaint(hWnd, hPS);
  67.         WinEndPaint( hPS );
  68.             break;
  69.  
  70.         case WM_ERASEBACKGROUND:    /* have PM take care of background */
  71.             return(TRUE);
  72.             break;
  73.  
  74.         default:        /* all other messages go here */
  75.             return( WinDefWindowProc( hWnd, msg, mp1, mp2 ) );
  76.             break;
  77.     }
  78.     return(0L);
  79. }
  80.  
  81. void MainWndPaint(HWND hWnd, HPS hPS)
  82. {
  83.  
  84.   /* Print a string in the icon area */
  85.  
  86. /* 
  87.   If Microsoft ever gets WinQueryWindowPos working correctly, then
  88.   replace the line 'if (WindowIsIconic(hWnd))' with the following: 
  89. */
  90. /*
  91.     SWP swp;
  92.  
  93.     WinQueryWindowPos(hWnd, &swp);
  94.  
  95.     if ((swp.fs & SWP_MINIMIZE) && (!(swp.fs & SWP_MAXIMIZE))) {
  96. */
  97.  
  98.     if (WindowIsIconic(hWnd)) {
  99.         POINTL pt;
  100.     pt.x = 0;
  101.       pt.y = 0;
  102.     GpiMove(hPS, (PPOINTL)&pt);
  103.     pt.x = xIconsize-1;
  104.     pt.y = yIconsize-1;
  105.         GpiBox(hPS, 2L, (PPOINTL)&pt, 0L, 0L);
  106.         pt.x = 0;
  107.         pt.y = 2 * (yIconsize - CharHeight) / 3;
  108.         GpiCharStringAt( hPS, (PPOINTL)&pt, (LONG)strlen(szIcon), (PCH)szIcon);
  109.     }
  110. }
  111.  
  112. /* 
  113.    Return TRUE if main window is iconic.
  114.    This kludge is needed since WinQueryWindowPos is not yet fully implemented.
  115. */
  116. BOOL WindowIsIconic(HWND hWnd)
  117. {
  118.  
  119.     RECTL cRect;
  120.  
  121.   /* get the current window client rectangle */
  122.     WinQueryWindowRect(hWnd, (PRECTL)&cRect);
  123.  
  124.   /* compare with size when window is iconic */
  125.     if ((cRect.xRight == xIconsize) && (cRect.yTop == yIconsize))
  126.     return TRUE;
  127.  
  128.     return FALSE;
  129. }
  130.